package main

func maxSubArray(nums []int) int {
	max := nums[0]
	oldSum := max
	for i := 1; i < len(nums); i++ {
		if oldSum < 0 {
			oldSum = nums[i]
		} else {
			oldSum += nums[i]
		}

		if oldSum > max {
			max = oldSum
		}

	}

	return max
}
